package com.example.demo;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import rx.Subscriber;

@RestController
public class CallerController {
	@Autowired
	SentenceService sentenceService;

	@RequestMapping("/")
	public String getResult() {

		// List<String> nounList = new ArrayList<>();
		//
		// sentenceService.getActivity().subscribe(new Subscriber<String>() {
		//
		// @Override
		// public void onCompleted() {
		// }
		//
		// @Override
		// public void onError(Throwable arg0) {
		// }
		//
		// @Override
		// public void onNext(String arg0) {
		// nounList.add(arg0);
		// }
		//
		// });//这样显然是错误的，因为请求发起之后采取异步的订阅获取noun，return是nounList始终为空
		try {
			return sentenceService.getWord().get() + " " + sentenceService.getActivity();
		} catch (Exception e) {
			return "qweq";
		}
	}

}

// Feign
// @RestController
// public class CallerController {
//
// @Autowired
// SubjectClient subjectClient;
// @Autowired
// ActivityClient activityClient;
//// LoadBalancerClient client;//Ribbon
//// DiscoveryClient client;//Default Eureka Dicovery(Client)
//
// @RequestMapping("/")
// public String getResult() {
// return getWord() + activityClient.getActivity();
//// return getService("mmb-eureka-client-subject") + " "
// +getService("mmb-eureka-client-activity");
// }
//
// private String getWord() {
// try {
// return subjectClient.getWord();
// }catch(Exception e) {
// return "None";
// }
// }
//
// //Default Eureka Dicovery(Client)
//// private String getService(String serviceName) {
//// List<ServiceInstance> services = client.getInstances(serviceName);
//// if(services != null && services.size()> 0) {
//// URI uri = services.get(0).getUri();
//// if(uri != null) {
//// return (new RestTemplate()).getForObject(uri, String.class);
//// }
//// }
//// return "None";
//// }
//
// //Ribbon
//// private String getService(String serviceName) {
//// ServiceInstance service = client.choose(serviceName);
//// if(service != null ) {
//// return (new RestTemplate()).getForObject(service.getUri(), String.class);
//// }
//// return "None";
//// }
//
// }
